package com.ljtxxhwj.myblob.service.impl;

import com.ljtxxhwj.myblob.entity.ArticleKind;
import com.ljtxxhwj.myblob.entity.ArticleKindExample;
import com.ljtxxhwj.myblob.entity.ArticleTag;
import com.ljtxxhwj.myblob.entity.ArticleTagExample;
import com.ljtxxhwj.myblob.mapper.ArticleTagMapper;
import com.ljtxxhwj.myblob.service.ArticleTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ljtxxhwj
 * @since 2024-07-19
 */
@Service
public class ArticleTagServiceImpl implements ArticleTagService {
    @Autowired
    private ArticleTagMapper articleTagMapper;

    @Override
    public List<ArticleTag> findAllArticleTag() {
        List<ArticleTag> articleTagList=articleTagMapper.selectByExample(null);

        return articleTagList;
    }

    @Override
    public List<ArticleTag> findByTagName(String tagName) {
        ArticleTagExample example=new ArticleTagExample();
        example.createCriteria().andArticleTagNameLike("%"+tagName+"%");
        List<ArticleTag> articleTagList= articleTagMapper.selectByExample(example);
        return articleTagList;
    }

    @Override
    public void deleteByArticleTagId(Integer articleTagId) {
        //删除标签
        articleTagMapper.deleteByPrimaryKey(articleTagId);
    }

    @Override
    public void saveTag(ArticleTag articleTagName) {
        articleTagMapper.insert(articleTagName);
    }

    @Override
    public int deleteBatch(String[] ids) {
        System.out.println("ids = " + ids);
        for (String id : ids) {
            System.out.println("id = " + id);

            articleTagMapper.deleteRelationKey(Integer.valueOf(id));

            articleTagMapper.deleteByPrimaryKey(Integer.valueOf(id));
        }
        return 1;
    }
}
